package robocup.component.infotypes;

/**
 * <code>VisualObjectInfo</code> is a basic type (abstract) for all visible
 * objects of players (not for coach).
 */
public abstract class VisualObjectInfo
    extends Info
    implements Comparable {

  /**
   * The id of the object.
   */
  protected int    id;

  /**
   * The distance, in which the object was seen.
   */
  protected double distance;

  /**
   * The direction, in which the object was seen.
   */
  protected double direction;

  /**
   * <code>VisualObjectInfo</code> constructor Any visual object (line, flag,
   * ball, player)
   * 
   * @param cycle -
   *          time (of perceiving)
   * @param iId -
   *          its id
   * @param iDistance -
   *          its relative distance to the sensing agent
   * @param iDirection -
   *          its relative direction to the sensing agent
   */
  public VisualObjectInfo(
      final int cycle,
      final int iId,
      final double iDistance,
      final double iDirection) {

    super(cycle);
    this.id = iId;
    this.distance = iDistance;
    this.direction = iDirection;
  }

  /**
   * <code>getDirection</code>
   * 
   * @return Returns the direction.
   */
  public final double getDirection() {

    return this.direction;
  }

  /**
   * <code>getDistance</code>
   * 
   * @return Returns the distance.
   */
  public final double getDistance() {

    return this.distance;
  }

  /**
   * <code>getId</code>
   * 
   * @return Returns the id.
   */
  public final int getId() {

    return this.id;
  }

  /**
   * <code>compareTo</code> from interface java.lang.Comparable. The
   * comparison is based on the <code>distance</code> attribute.
   * 
   * @param o -
   *          the Object to be compared
   * @return negative integer, zero, or a positive integer as this objects
   *         <code>distance</code> is less than, equal to, or greater than
   *         <code>distance</code> of the specified object.
   * @throws ClassCastException
   *           if the specified object's type prevents it from being compared to
   *           this Object.
   */
  public final int compareTo(final Object o) throws ClassCastException {

    final VisualObjectInfo voi = (VisualObjectInfo) o;
    final double dist = voi.getDistance();
    // o greater than this
    if (dist > this.distance) {
      return -1;
    } // end if
    // o less than this
    if (dist < this.distance) {
      return 1;
    } // end if
    // o equals this
    return 0;
  }

  /**
   * Sets the direction, in which the object was seen.
   * 
   * @param direction
   */
  public void setDirection(final double direction) {

    this.direction = direction;
  }

  /**
   * Sets the distance, in which the object was seen.
   * 
   * @param distance
   */
  public void setDistance(final double distance) {

    this.distance = distance;
  }

  /**
   * Sets the id of the object (especially necessary for lines and flags).
   * 
   * @param id
   */
  public void setId(final int id) {

    this.id = id;
  }
}
